package star.cloud.asme.flowable.processDefinition;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import star.cloud.asme.base.dto.Result;
import star.cloud.asme.base.fowable.baseInterface.FlowableBaseController;
import star.cloud.asme.base.fowable.VO.ProcessDefinitionQueryCondition;
import star.cloud.asme.base.fowable.VO.ProcessDefinitionVO;

@RestController
@RequestMapping("/flowable/processDefinition")
@RequiredArgsConstructor
public class HqProcessDefinitionController implements FlowableBaseController<ProcessDefinitionQueryCondition, ProcessDefinitionVO> {

    private final HqProcessDefinitionService hqProcessDefinitionService;

    @Override
    public Result<ProcessDefinitionVO> getOneByCondition(@PathVariable String key, @PathVariable Object value) {
        return hqProcessDefinitionService.getOneByCondition(key, value);
    }

    @Override
    public Result<IPage<ProcessDefinitionVO>> getListByConditionsWithPage(ProcessDefinitionQueryCondition conditions) {
        return hqProcessDefinitionService.getListByConditionsWithPage(conditions);
    }

    @PostMapping("/deploy")
    public Result<ProcessDefinitionVO> deploy(MultipartFile file, ProcessDefinitionVO processDefinitionVO) {
        return hqProcessDefinitionService.deploy(file, processDefinitionVO);
    }

    //暂停一个流程定义
    @DeleteMapping("/suspendProcessDefinition/{type}/{value}")
    public Result<?> suspendProcessDefinition(@PathVariable String type, @PathVariable String value) {
        return hqProcessDefinitionService.suspendProcessDefinition(type, value);
    }

    //激活一个流程定义
    @GetMapping("/activateProcessDefinition/{type}/{value}")
    Result<?> activateProcessDefinition(@PathVariable String type, @PathVariable String value) {
        return hqProcessDefinitionService.activateProcessDefinition(type, value);
    }

    @Override
    public Result<?> physicalDeleteById(String processDefinitionId) {
        System.out.println("processDefinitionId = " + processDefinitionId);
        return hqProcessDefinitionService.physicalDelete(processDefinitionId);
    }

}
